package Application.Widgets.TextFileds;

import Application.Utils.StaticUtil;
import Application.Widgets.Override.LabelOverride;

import javax.swing.*;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import java.awt.*;

public class TextFiledString extends JTextField
{
    private String WidgetName = "";
    private String BaseValue;

    public TextFiledString(String baseValue,int columns)
    {
        this.BaseValue = baseValue;
        this.setFont(StaticUtil.config.fontGetter());
        this.setColumns(columns);
    }
    public TextFiledString(String baseValue)
    {
        this(baseValue,100);
    }
    public TextFiledString(String baseValue,String Name)
    {
        this(baseValue);
        this.WidgetName = Name;
    }
    public TextFiledString(String baseValue,String Name,JComponent component)
    {
        this(baseValue,Name);
        component.add(this);
    }
    public TextFiledString(String baseValue,String Name,JComponent component,String LayoutPlace)
    {
        this(baseValue,Name);
        component.add(this,LayoutPlace);
    }
    public TextFiledString(String title,String baseValue,String Name,JComponent component)
    {
        this(baseValue,Name);
        LabelOverride label = new LabelOverride(title,component);
        component.add(this);
    }

    public void setWidgetName(String name)
    {
        this.WidgetName = name;
    }
    public String getWidgetName() {return this.WidgetName;}

    public String getValue()
    {
        String value = BaseValue;
        if (!this.getText().equals("") && this.getText() != null)
        {
            value = this.getText();
        }else
        {
            StaticUtil.errorReport.append("系统：参数不能为空或者不合法！位置："+this.getWidgetName()+"\n");
            this.setText(String.valueOf(BaseValue));
        }
        return value;
    }
}
